package com.chixing.day08.InterFaceDemo;

/**
 * 把 A implements Comparable<T> 比较两个对象的先后顺序
 * 实现了自然顺序
 */

public class Product implements Comparable<Product> {
    private String proName;
    private int proSale;
    private float proPrice;

    public Product() {
    }

    public Product(String proName, int proSale, float proPrice) {
        this.proName = proName;
        this.proSale = proSale;
        this.proPrice = proPrice;
    }

    //两个商品比较先后顺序(先比较销量、再比较价格,再比较商品名称)

    @Override
    public int compareTo(Product anotherProduct) {
        if (anotherProduct.proSale != this.proSale) {
            return this.proSale - anotherProduct.proSale;
        } else if (anotherProduct.proPrice != this.proPrice) {
            return (int) (this.proPrice - anotherProduct.proPrice);
        } else {
            return this.proName.compareTo(anotherProduct.proName);
        }
    }
}

